var ctx;
var complainType;

function setCtx(ctx) {
	this.ctx = ctx;
}

//返回上一页
function cancel(){
	complainType = $("#complainType").val();
	loadContent("/complainInfo/infoList?complainType="+complainType);
}

//验证自定义标题
function checkSelfTitle(){
	var selfTitle = $("#selfTitle").val();
	//解决ie9以下placeholder与value重复的问题
	if(selfTitle == $("#selfTitle").attr("placeholder")){
		selfTitle = "";
	}
	if(selfTitle == null || selfTitle == ""){
		layer.tips('标题不能为空!', '#selfTitle', {
		    tips: 3,
		    time:1000
		});
		return false;
	}else{
		return true;
	}
}

//验证默认标题
function checkNormalTitle(){
	var normalTitle = $("#normalTitle").val();
	//解决ie9以下placeholder与value重复的问题
	if(normalTitle == $("#normalTitle").attr("placeholder")){
		normalTitle = "";
	}
	if(normalTitle == null || normalTitle == ""){
		layer.tips('标题不能为空!', '#normalTitle', {
		    tips: 3,
		    time:1000
		});
		return false;
	}else{
		return true;
	}
}

function changeContent (obj){
    var c = $("#normalCont").find("option:selected").attr("content");
	$('#normalContent').val(c);
}

function changeType (type) {
	var type = $('#replyType').val();
	if ( type ==1 ) {
		$('#normal').show();
		$('#self').hide();
	} else {
		$('#self').show();
		$('#normal').hide();
	}
}

//实现字段较长时的隐藏于显示
var index1;
function mouseOverCon(item , con){
	index1 = layer.tips(con, '#content' + item, {
		  tips: [3, '#37CED4']
		});
}

function mouseOutCon(item , con){
	layer.close(index1);
}

//增加回复信息
var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
function saveReply(infoId){
replyType=$('#replyType').val();
complainType=$('#complainType').val();
	//标准回复
	if(replyType == 1){
		title=$('#normalTitle').val();
		content=$('#normalContent').val();
		//解决ie9以下placeholder与value重复的问题
		if(content == $("#normalContent").attr("placeholder")){
			content = "";
		}
	}
	//自定义回复
	if(replyType == 2){
		title=$('#selfTitle').val();
		content=$('#selfCotent').val();
		//解决ie9以下placeholder与value重复的问题
		if(title == $("#selfTitle").attr("placeholder")){
			title = "";
		}
		if(content == $("#selfCotent").attr("placeholder")){
			content = "";
		}
	}
	
	rmemo=$('#memo').val();
	if(rmemo == $("#memo").attr("placeholder")){
		rmemo = "";
	}

	if((replyType == 1 && checkNormalTitle()) || (replyType == 2 && checkSelfTitle())){
		var index1 = layer.load(1);
		$.post(ctx + "/complainReply/saveReply", {
			infoId:infoId,
			title:title,
			content :content,
			type :1,
			memo:rmemo
		}, function(data) {
			data = JSON.parse(data);
			if (data.success) {
				layer.msg("操作成功",{
					icon: 1,
					time: 1000 //2秒关闭（如果不配置，默认是3秒）
				},function(){
					parent.loadContent("/complainInfo/infoList?complainType=" + complainType);
					parent.layer.close(index);
				});
			} else {
				layer.close(index1);
				layer.msg("操作失败",{
					icon: 2
				});
			}
		});
	}
	/*$.ajax({
		type : "POST",
		url : ctx + "/complainReply/saveReply",
		cache : false,
		dataType : 'json',
		data: {
			infoId:infoId,
			title:rtitle,
			content :rcontent,
			type :1,
			memo:rmemo
		},
		success : function(result) {
			if (result.success) {
				layer.msg("操作成功",{
					icon: 1,
					time: 1000 //2秒关闭（如果不配置，默认是3秒）
				},function(){
					parent.loadContent("/complainInfo/infoList");
					parent.layer.close(index);
				});
			} else {
				layer.msg("操作失败",{
					icon: 2
				});
			}
		}
	});*/
}

